<?php
try {
    $mongodb = new MongoClient();
    $articleCollection = $mongodb->blog->articles;
}catch(MongoConnectionException $e) {
    die('Failed to connect to MongoDB ' . $e->getMessage());
}
$cursor = $articleCollection->find(array(), array('title','content','saved_at'));
$cursor->sort(array('saved_at' => - 1));

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="bootstrap.css" />
    <link rel="stylesheet" href="style.css" />
    <title>MongoBeer</title>
</head>
<body>
<div id="contentarea">
    <div id="innercontentarea">
        <h1>MongoBeer</h1>
        <br/>
        <?php
        while ($cursor->hasNext()):
            $article = $cursor->getNext();
            ?>
            <h3>
                <?php
                echo $article['title'];
                ?>
            </h3>
            <p>
                <?php
                echo substr($article['content'], 0, 200) . '...';
                ?>
            </p>
            <a href="blog.php?id=<?php echo $article['_id'];?>">> Lire la suite</a>
        <?php
        endwhile;
        ?>
    </div>
</div>
<div id="footer">
    <p>
        <a href="index.php">Accueil</a> -
        <a href="blogpost.php">Poster un article</a> -
        <a href="admin.php">Administration</a>
    </p>
</div>
</body>
</html